# DK_means_DK_replication.R
# Created 2011 05 15 by John G. Bullock

# Creates Tables 1-3 in Robert C. Luskin and John G. Bullock, "'Don't Know' 
# Means 'Don't Know': DK Responses and the Public's Level of Political 
# Knowledge," Journal of Politics 73 (April): 547-57, 
# http://dx.doi.org/10.1017/S0022381611000132.

library(car)      # supplies recode()
library(foreign)  # supplies read.spss()
lNA    <- function (x) length(x[!is.na(x)])
meanNA <- function (x) mean(x, na.rm=TRUE)
sumNA  <- function (x) sum(x, na.rm=TRUE) 

# LOAD TESS DATA
DK <- read.spss('TESS_final/DK.sav', use.value.labels=FALSE, to.data.frame=TRUE, use.missings=FALSE)
names(DK) <- tolower(names(DK))

# LOAD 2000 ANES DATA
ANES.2000 <- read.spss('anes_2000prepost.sav', use.value.labels=FALSE)

                   

#####################################################################
# CODE TESS INDEPENDENT KNOWLEDGE QUESTIONS (GIVEN SAME WAY TO ALL 
# RESPONDENTS)
#####################################################################
cheney      <- recode(DK$cheney,"2=0;c(8,9)=NA;8=8")
const       <- recode(DK$constita,"1:3=0;4=1;8=8;else=NA")
veto        <- recode(DK$veto,"1=1;NA=NA;8=8;else=0")        
abortion    <- recode(DK$abortion,"1=1;NA=NA;8=8;else=0")
bushmed     <- recode(DK$bush,"3=1;NA=NA;8=8;else=0")
kerrymed    <- recode(DK$kerry,"1=1;NA=NA;8=8;else=0")
leastspend  <- recode(DK$spenda,"2=1;NA=NA;8=8;else=0")
know.ind    <- cbind(cheney,const,veto,abortion,bushmed,kerrymed,leastspend)



#####################################################################
# CODE TESS DEPENDENT KNOWLEDGE QUESTIONS
# (DK-ENCOURAGING, NEUTRAL, OR DISCOURAGING VERSIONS)
#####################################################################
condition <- factor(DK$bul_con,labels=c("encourage","neutral","discourage"))
ensenate  <- recode(DK$ensenate,"3=1;8=8;NA=NA;else=0")
enjudge   <- recode(DK$enjudge,"1=1;8=8;NA=NA;else=0")
endefic   <- recode(DK$endefic,"3=1;8=8;NA=NA;else=0")
nesenate  <- recode(DK$nesenate,"3=1;8=8;NA=NA;else=0")
nejudge   <- recode(DK$nejudge,"1=1;8=8;NA=NA;else=0")
nedefic   <- recode(DK$nedefic,"3=1;8=8;NA=NA;else=0")
dissenate <- recode(DK$dissenat,"3=1;8=8;NA=NA;else=0")
disjudge  <- recode(DK$disjudge,"1=1;8=8;NA=NA;else=0")
disdefic  <- recode(DK$disdefic,"3=1;8=8;NA=NA;else=0")

responses <- c(ensenate,enjudge,endefic)
responses[!is.na(c(nesenate,nejudge,nedefic))]    <- c(nesenate,nejudge,nedefic)[!is.na(c(nesenate,nejudge,nedefic))]
responses[!is.na(c(dissenate,disjudge,disdefic))] <- c(dissenate,disjudge,disdefic)[!is.na(c(dissenate,disjudge,disdefic))]
responses <- factor(responses,labels=c('wrong','correct','DK'))
senate    <- responses[1:1507]
judge     <- responses[1508:3014]
deficit   <- responses[3015:4521]

en        <- cbind(ensenate,enjudge,endefic)
ne        <- cbind(nesenate,nejudge,nedefic)
dis       <- cbind(dissenate,disjudge,disdefic)



###########################################################################
# TABLE 1: RESPONSES TO CLOSED-ENDED KNOWLEDGE ITEMS IN THE TESS EXPERIMENT
###########################################################################
# This code creates tables that indicate the percentages of people 
# responding correctly, incorrectly, or "don't know" to knowledge 
# items in DK-encouraging, DK-discouraging, and DK-neutral conditions.
rownames <- c("ensenate", "nesenate", "dissenate", "enjudge", "nejudge", "disjudge", 
              "endefic", "nedefic", "disdefic", "en", "ne", "dis", 
              colnames(know.ind), "know.ind")
T1 <- matrix(NA,length(rownames),3,dimnames=list(rownames,c("% right","% wrong","% DK"))) 
for (i in 1:length(rownames)) {
  q <- get(rownames[i])
  T1[i, "% right"] <- sum(q==1, na.rm=TRUE)/lNA(q)
  T1[i, "% wrong"] <- sum(q==0, na.rm=TRUE)/lNA(q)
  T1[i, "% DK"]    <- sum(q==8, na.rm=TRUE)/lNA(q)
}
round(T1, 3)



###########################################################################
# TABLE 2: HIDDEN KNOWLEDGE VS. LUCKY GUESSING ON CLOSED-ENDED ITEMS IN THE 
# TESS EXPERIMENT
###########################################################################
T2 <- matrix(NA, nrow=4, ncol=9, 
             dimnames=list(c('senate', 'judgenom', 'deficit', 'mean'), 
                           c('correct.en', 'correct.ne', 'correct.dis', 
                             'blind.en', 'blind.ne', 'imp.en', 'imp.ne', 
                             'guess.en', 'guess.ne')))
T2['senate',   1:3] <- tapply(senate=='correct',  condition, meanNA)
T2['judgenom', 1:3] <- tapply(judge=='correct',   condition, meanNA)
T2['deficit',  1:3] <- tapply(deficit=='correct', condition, meanNA)            
T2['senate',   'guess.en'] <- (1/4)*(meanNA(ensenate==8) - meanNA(dissenate==8))
T2['judgenom', 'guess.en'] <- (1/4)*(meanNA(enjudge==8)  - meanNA(disjudge==8))
T2['deficit',  'guess.en'] <- (1/3)*(meanNA(endefic==8)  - meanNA(disdefic==8))
T2['senate',   'guess.ne'] <- (1/4)*(meanNA(nesenate==8) - meanNA(dissenate==8))
T2['judgenom', 'guess.ne'] <- (1/4)*(meanNA(nejudge==8)  - meanNA(disjudge==8))
T2['deficit',  'guess.ne'] <- (1/3)*(meanNA(nedefic==8)  - meanNA(disdefic==8))
T2[1:3, 'blind.en'] <- T2[1:3, 'correct.en']  + T2[1:3, 'guess.en']
T2[1:3, 'blind.ne'] <- T2[1:3, 'correct.ne']  + T2[1:3, 'guess.ne']
T2[1:3, 'imp.en']   <- T2[1:3, 'correct.dis'] - T2[1:3, 'blind.en']
T2[1:3, 'imp.ne']   <- T2[1:3, 'correct.dis'] - T2[1:3, 'blind.ne']
T2['mean',] <- apply(T2[1:3,], 2, mean)
round(T2, 3)



###########################################################################
# TABLE 3: DK-DISCOURAGING VERSUS DK-NEUTRAL RESPONSES TO OPEN-ENDED ITEMS
# IN THE 2000 ANES EXPERIMENT
###########################################################################

# Experimental knowledge variables.  The first set are name recognition items, 
# coded 0/1/8 (incorrect, correct, no attempt to guess).  They are the FINAL 
# answers -- including answers after probing for those who were probed.
blair     <- recode(ANES.2000$V001453, "5=0;9=8;0=NA") 
lott      <- recode(ANES.2000$V001447, "5=0;9=8;0=NA")
rehnquist <- recode(ANES.2000$V001450, "5=0;9=8;0=NA")
reno      <- recode(ANES.2000$V001456, "5=0;9=8;0=NA")

# Answers for people assigned to the "standard" (no probe) condition
blair.standard     <- recode(ANES.2000$V001452A, '5=0;9=8;0=NA')
lott.standard      <- recode(ANES.2000$V001446A, '5=0;9=8;0=NA')
rehnquist.standard <- recode(ANES.2000$V001449A, '5=0;9=8;0=NA')
reno.standard      <- recode(ANES.2000$V001455A, '5=0;9=8;0=NA')

# FINAL answers for people assigned to the "experimental" (probe DKs) 
# condition.  Some of these people were probed; others were not, even if they 
# said DK.
blair.experimental.final     <- recode(ANES.2000$V001452B, '5=0;9=8;0=NA')
lott.experimental.final      <- recode(ANES.2000$V001446B, '5=0;9=8;0=NA')
rehnquist.experimental.final <- recode(ANES.2000$V001449B, '5=0;9=8;0=NA')
reno.experimental.final      <- recode(ANES.2000$V001455B, '5=0;9=8;0=NA')

# Respondent initially said DK in a DK-discouraging condition and was then 
# probed?  
blair.probed     <- recode(as.numeric(ANES.2000$V001454), '0=NA')==1
lott.probed      <- recode(as.numeric(ANES.2000$V001448), '0=NA')==1
rehnquist.probed <- recode(as.numeric(ANES.2000$V001451), '0=NA')==1
reno.probed      <- recode(as.numeric(ANES.2000$V001457), '0=NA')==1

# Respondent initially said DK in a DK-discouraging condition and was *not* 
# then probed?  (Note: the NES interviewers were told to probe only DK, not 
# "RF" answers.  If RFs were treated as a separate category in this file, 
# these results would be slightly different.)
table(blair.experimental.final==8 & !blair.probed)
table(lott.experimental.final==8 & !lott.probed)
table(rehnquist.experimental.final==8 & !rehnquist.probed)
table(reno.experimental.final==8 & !reno.probed)

# Respondent initially said DK (or RF, which we are counting as DK) in a 
# DK-discouraging condition?  (The numbers in the TRUE category are the 
# numbers of such respondents.  The numbers in the FALSE category have no 
# special meaning.)
table(blair.experimental.final==8 | blair.probed)
table(lott.experimental.final==8 | lott.probed)
table(rehnquist.experimental.final==8 | rehnquist.probed)
table(reno.experimental.final==8 | reno.probed)

# Final answers for those who said DK in a DK-discouraging condition
# and were probed.
table(blair.experimental.final[blair.probed])
table(lott.experimental.final[lott.probed])
table(rehnquist.experimental.final[rehnquist.probed])
table(reno.experimental.final[reno.probed])

# Create Table 3.
T3 <- matrix(NA, nrow=5, ncol=9, 
                   dimnames=list(c('Blair', 'Lott', 'Rehnquist', 'Reno', 'Mean'),
                                 c('wrong.ne', 'correct.ne', 'DK.ne', 'wrong.dis', 'correct.dis', 'DK.dis', 'wrong.probed', 'correct.probed', 'DK.probed')))
T3[1:4,    1:3] <- rbind(table(blair.standard), table(lott.standard), table(rehnquist.standard), table(reno.standard))
T3['Mean', 1:3] <- apply(T3[1:4, 1:3], 2, sum)/sum(T3[1:4, 1:3]) 
T3[1:4,    4:6] <- rbind(table(blair.experimental.final), 
                               table(lott.experimental.final), 
                               table(rehnquist.experimental.final), 
                               table(reno.experimental.final))
T3['Mean', 4:6] <- apply(T3[1:4, 4:6], 2, sum)/sum(T3[1:4, 4:6]) 
T3[1:4,    7:9] <- rbind(table(blair.experimental.final[blair.probed]),
                               table(lott.experimental.final[lott.probed]),
                               table(rehnquist.experimental.final[rehnquist.probed]),
                               table(reno.experimental.final[reno.probed]))
T3['Mean', 7:9] <- apply(T3[1:4, 7:9], 2, sum)/sum(T3[1:4, 7:9]) 
round(T3, 3)



# > sessionInfo()
# R version 2.11.1 (2010-05-31) 
# i386-pc-mingw32 
#
# locale:
# [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
# [4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    
#
# attached base packages:
# [1] stats     graphics  grDevices utils     datasets  methods   base     
#
# other attached packages:
# [1] rj_0.5.0-5
#
# loaded via a namespace (and not attached):
# [1] rJava_0.8-8  tools_2.11.1
